package com.simple.mipc.utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MethodUtil {

    public static <T> T invoke(Object instance, Method method, Object...objects) {
        boolean accessible = method.isAccessible();
        try {
            method.setAccessible(true);
            return (T) method.invoke(instance, objects);
        } catch (InvocationTargetException | IllegalAccessException e) {
            throw new RuntimeException(e);
        } finally {
            method.setAccessible(accessible);
        }
    }
}
